/*
 * Copyright (c) 2023 CHANGLEI. All rights reserved.
 */

package com.graspyun.plugin.tverify

import android.content.Context
import com.rich.oauth.core.UIConfigBuild
import io.flutter.plugin.common.MethodChannel

/**
 * Created by changlei on 2023/8/15.
 * <p>
 * UIConfig
 */
fun createUIConfigBuild(context: Context, channel: MethodChannel, map: Map<*, *>): UIConfigBuild {
    val builder = UIConfigBuild.Builder()
    (map["privacyBookSymbol"] as Boolean?)?.apply {
        builder.privacyBookSymbol = this
    }
    (map["isPrivacyAnimation"] as Boolean?)?.apply {
        builder.privacyAnimationBoolean = this
    }
    (map["authuncheckway"] as String?)?.apply {
        builder.authuncheckway = this
    }
    (map["privacyAnimationbool"] as Boolean?)?.apply {
        builder.privacyAnimationBoolean = this
    }
    (map["isWindowBackButtonWorks"] as Boolean?)?.apply {
        builder.isWindowBackButtonWroks = this
    }
    (map["loginBtnBg"] as String? ?: "selector_button_background").apply {
        builder.loginBtnBg = context.getDrawableId(this)
    }
    (map["loginBtnText"] as String?)?.apply {
        builder.loginBtnText = this
    }
    (map["loginBtnTextColor"] as Number?)?.apply {
        builder.loginBtnTextColor = this.toInt()
    }
    (map["loginBtnTextSize"] as Number?)?.apply {
        builder.loginBtnTextSize = this.toInt()
    }
    (map["loginbtnTextBold"] as Boolean?)?.apply {
        builder.loginbtnTextBold = this
    }
    (map["switchTextColor"] as Number?)?.apply {
        builder.switchTextColor = this.toInt()
    }
    (map["switchIsHide"] as Boolean?)?.apply {
        builder.switchIsHide = this
    }
    (map["isProtocolSeleted"] as Boolean?)?.apply {
        builder.isProtocolSelected = this
    }
    (map["switchText"] as String?)?.apply {
        builder.switchText = this
    }
    (map["privacyContentText"] as String?)?.apply {
        builder.privacyContentText = this
    }
    (map["checkTipText"] as String?)?.apply {
        builder.checkTipText = this
    }
    (map["protocolName"] as String?)?.apply {
        builder.protocolName = this
    }
    (map["protocolUrl"] as String?)?.apply {
        builder.protocolUrl = this
    }
    (map["secondProtocolName"] as String?)?.apply {
        builder.secondProtocolName = this
    }
    (map["secondProtocolUrl"] as String?)?.apply {
        builder.secondProtocolUrl = this
    }
    (map["thirdProtocolName"] as String?)?.apply {
        builder.thirdProtocolName = this
    }
    (map["thirdProtocolUrl"] as String?)?.apply {
        builder.thirdProtocolUrl = this
    }
    (map["loginButtonWidth"] as Number?)?.apply {
        builder.loginButtonWidth = this.toInt()
    }
    (map["loginButtonHight"] as Number?)?.apply {
        builder.loginButtonHight = this.toInt()
    }
    (map["privacyColor"] as Number?)?.apply {
        builder.privacyColor = this.toInt()
    }
    (map["privacyOtherTextColor"] as Number?)?.apply {
        builder.privacyOtherTextColor = this.toInt()
    }
    (map["statusBarBgColor"] as Number?)?.apply {
        builder.statusBarBgColor = this.toInt()
    }
    (map["statusBarTextColor"] as Boolean?)?.apply {
        builder.statusBarTextColor = this
    }
    (map["fitsSystemWindows"] as Boolean?)?.apply {
        builder.fitsSystemWindows = this
    }
    (map["navColorBgColor"] as Number?)?.apply {
        builder.privacyNavBgColor = this.toInt()
    }
    (map["ouathStateTextColor"] as Number?)?.apply {
        builder.ouathStateTextColor = this.toInt()
    }
    (map["numberColor"] as Number?)?.apply {
        builder.numberColor = this.toInt()
    }
    (map["numberSize"] as Number?)?.apply {
        builder.numberSize = this.toInt()
    }
    (map["numberOffsetX"] as Number?)?.apply {
        builder.numberOffsetX = this.toInt()
    }
    (map["numFieldOffsetY"] as Number?)?.apply {
        builder.numFieldOffsetY = this.toInt()
    }
    (map["numFieldOffsetYB"] as Number?)?.apply {
        builder.numFieldOffsetY_B = this.toInt()
    }
    (map["numberBold"] as Boolean?)?.apply {
        builder.numberBold = this
    }
    (map["logBtnOffsetYB"] as Number?)?.apply {
        builder.logBtnOffsetY_B = this.toInt()
    }
    (map["logBtnOffsetY"] as Number?)?.apply {
        builder.logBtnOffsetY = this.toInt()
    }
    (map["privacyOffsetY"] as Number?)?.apply {
        builder.privacyOffsetY = this.toInt()
    }
    (map["privacyOffsetYB"] as Number?)?.apply {
        builder.privacyOffsetY_B = this.toInt()
    }
    (map["privacyMarginLeft"] as Number?)?.apply {
        builder.privacyMarginLeft = this.toInt()
    }
    (map["privacyMarginRight"] as Number?)?.apply {
        builder.privacyMarginRight = this.toInt()
    }
    (map["privacyTextSize"] as Number?)?.apply {
        builder.privacyTextSize = this.toInt()
    }
    (map["clauseBaseColor"] as Number?)?.apply {
        builder.clauseBaseColor = this.toInt()
    }
    (map["clauseColor"] as Number?)?.apply {
        builder.clauseColor = this.toInt()
    }
    (map["isGravityCenter"] as Boolean?)?.apply {
        builder.isGravityCenter = this
    }
    (map["privacyNavTextSize"] as Number?)?.apply {
        builder.privacyNavTextSize = this.toInt()
    }
    (map["privacyNavClauseLayoutResID"] as String?)?.apply {
        builder.privacyNavClauseLayoutResID = context.getLayoutId(this)
    }
    (map["privacyNavBgColor"] as Number?)?.apply {
        builder.privacyNavBgColor = this.toInt()
    }
    (map["privacyNavTextColor"] as Number?)?.apply {
        builder.privacyNavTextColor = this.toInt()
    }
    (map["checkBoxLocation"] as Number?)?.apply {
        builder.checkBoxLocation = this.toInt()
    }
    (map["checkBoxImageWidth"] as Number?)?.apply {
        builder.checkBoxImageWidth = this.toInt()
    }
    (map["checkBoxImageheight"] as Number?)?.apply {
        builder.checkBoxImageheight = this.toInt()
    }
    (map["isAutoClosAuthPage"] as Boolean?)?.apply {
        builder.isAutoClosAuthPage = this
    }
    (map["authPageActInAuthPagein"] as String?)?.apply {
        builder.authPageActIn_authPagein = this
    }
    (map["authPageActInLastPageOut"] as String?)?.apply {
        builder.authPageActIn_lastPageOut = this
    }
    (map["authPageActOutAuthPageOut"] as String?)?.apply {
        builder.authPageActOut_authPageOut = this
    }
    (map["authPageActOutNextPagein"] as String?)?.apply {
        builder.authPageActOut_nextPagein = this
    }
    (map["contentView"] as Map<*, *>?)?.apply {
        val child = toView(context, channel, this)
        builder.contentView = RootView(context, map).apply {
            removeAllViews()
            addView(child)
        }
    }
    (map["authPageWindowMode"] as Boolean?)?.apply {
        builder.authPageWindowMode = this
    }
    (map["authPageWindowWith"] as Number?)?.apply {
        builder.authPageWindowWith = this.toInt()
    }
    (map["authPageWindowHight"] as Number?)?.apply {
        builder.authPageWindowHight = this.toInt()
    }
    (map["authPageWindowOffsetX"] as Number?)?.apply {
        builder.authPageWindowOffsetX = this.toInt()
    }
    (map["authPageWindowOffsetY"] as Number?)?.apply {
        builder.authPageWindowOffsetY = this.toInt()
    }
    (map["authPageWindowThemeId"] as String?)?.apply {
        builder.authPageWindowThemeId = context.getStyleId(this)
    }
    (map["authPageWindowBottom"] as Number?)?.apply {
        builder.authPageWindowBottom = this.toInt()
    }
    (map["logBtnMarginLeft"] as Number?)?.apply {
        builder.logBtnMarginLeft = this.toInt()
    }
    (map["logBtnMarginRight"] as Number?)?.apply {
        builder.logBtnMarginRight = this.toInt()
    }
    (map["appLanguageType"] as Number?)?.apply {
        builder.appLanguageType = this.toInt()
    }
    return builder.build()
}